# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 23:45:53 2019

@author: Administrator
"""
import cv2
import numpy
import utils

def strokeEdges(src,dst,blurKsize = 7,edgeKsize = 5):
    if blurKsize >=3:
        blurredSrc = cv2.medianBlur(src,blurKsize)
        graySrc = cv2.cvtColor(blurredSrc,cv2.COLOR_BGR2GRAY)
    else:
        graySrc = cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)
    cv2.Laplacian(blurredSrc,cv2.CV_8U,graySrc,ksize = edgeKsize)
    normalizedInverseAlpha = (1.0/255)*(255-graySrc)
    channels = cv2.split(src)
    for channel in channels:
        channel[:] = channel * normalizedInverseAlpha
    cv2.merge(channels,dst)

class VConvolutionFilter(object):
    """A filter that applies a convolution to V(or all of BGR )."""
    
    def __init__(self,kernel):
        self._kernel = kernel
    
    def apply(self,src,dst):
        """Apply the filter with a BGR or gray source/destination."""
        cv2.filter2D(src,-1,self._kernel,dst)


class SharpenFilter(VConvolutionFilter):
    """A sharpen filter with a 1-pixel radius."""
    #锐化功能
    #边缘为黑，其他为白，可以加两个循环使不为0的像素点值变成255，就会明显很多
    def __init__(self):
        kernel = numpy.array([[-1,-1,-1],
                              [-1, 9,-1],
                              [-1,-1,-1]])
        VConvolutionFilter.__init__(self,kernel)
        
class FindEdgesFilter(VConvolutionFilter):
    """A edge-finding filter with a 1-pixel radius."""
    #边缘为白，其他为黑
    def __init__(self):
        kernel = numpy.array([[-1,-1,-1],
                              [-1, 8,-1],
                              [-1,-1,-1]])
        VConvolutionFilter.__init__(self,kernel)


class BlurFilter(VConvolutionFilter):
    """A blur filter with a 2-pixel radius."""
    #模糊功能
    def __init__(self):
        kernel = numpy.array([[0.04,0.04,0.04,0.04,0.04],
                              [0.04,0.04,0.04,0.04,0.04],
                              [0.04,0.04,0.04,0.04,0.04],
                              [0.04,0.04,0.04,0.04,0.04],
                              [0.04,0.04,0.04,0.04,0.04]])
        VConvolutionFilter.__init__(self,kernel)


class EmbossFilter(VConvolutionFilter):
    """An emboss filter with a 1-pixel radius."""
    #非对称卷积核进行滤波，图像略恶心
    #同时具有模糊和锐化功能    
    def __init__(self):
        kernel = numpy.array([[-2,-1, 0],
                              [-1, 1, 1],
                              [ 0, 1, 2]])
        VConvolutionFilter.__init__(self,kernel)




    
    